OpenRoads Designer CONNECT Edition SDK Help

Create Alignment using two points

This Code Snippet shows how to create a horizontal alignment between 2 points

Example


internal Alignment CreateAlignmentFromPoints()
        {
            //Feature definition and name 
            string featureName = "GeomBL";
            string featureDef = "Alignment\\Geom_Baseline";

            Bentley.GeometryNET.DPoint3d startPoint = new DPoint3d(707074.878, 231801.166, 0);
            Bentley.GeometryNET.DPoint3d endPoint = new DPoint3d(707960.529, 231734.769, 0);

            //creates a line from points
            Bentley.CifNET.LinearGeometry.Line line = Line.Create1(startPoint, endPoint);

            Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
            Bentley.CifNET.GeometryModel.SDK.GeometricModel gm = con.GetOrCreateGeometricModel();
            if (gm == null) return null;

            //Save changes made here to dgn
            con.StartTransientMode();

            //creates new alignment using line
            Bentley.CifNET.GeometryModel.SDK.Alignment al = gm.CreateAlignmentByLinearElement(line, true);

            //sets feature definition and feature name to alignment
            if (featureName != null && featureName != string.Empty && featureDef != null && featureDef != string.Empty)
            {
                al.SetFeatureDefinition(featureDef, featureName);
            }
            //save changes made here to dgn
            con.PersistTransients();
            return al;

        }

CreateAlignmentByLinearElement() of GeometricModel creates an alignment from a simple line created from 2 points. SetFeatureDefinition() sets the feature definition to an alignment.